using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Yorrick.FlickrMetadataSynchr.Data
{
    /// <summary>
    /// The metadata for a picture on a local drive.
    /// </summary>
    public class LocalPictureMetadata : PictureMetadata
    {
        #region Private fields
        /// <summary>
        /// The file name without path and extension.
        /// </summary>
        private string _fileNameWithoutExtension;

        /// <summary>
        /// The Flickr id.
        /// </summary>
        private string _flickrId = String.Empty;

        /// <summary>
        /// The original Flickr id.
        /// </summary>
        private string _flickrIdOriginal = String.Empty;
        #endregion

        #region Constructor
        /// <summary>
        /// Constructs an instance with the filepath as identifier.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        public LocalPictureMetadata(string filePath)
            : base(filePath)
        {
            _fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);
        }
        #endregion

        #region Public properties
        /// <summary>
        /// Gets the file path.
        /// </summary>
        public string FilePath
        {
            get
            {
                return Id;
            }
        }

        /// <summary>
        /// Gets the file name without path and extension.
        /// </summary>
        public string FileNameWithoutExtension
        {
            get
            {
                return _fileNameWithoutExtension;
            }
        }

        /// <summary>
        /// Gets or set the Flickr id.
        /// </summary>
        public string FlickrId
        {
            get
            {
                return _flickrId;
            }
            set
            {
                if (_flickrId != value)
                {
                    _flickrId = value;
                    if (!TrackChanges)
                    {
                        _flickrIdOriginal = value;
                    }
                    else
                    {
                        Changed = true;
                    }
                }
            }
        }

        /// <summary>
        /// Gets whether or not the Flickr id has changed.
        /// </summary>
        public bool FlickrIdChanged
        {
            get
            {
                return (_flickrId != _flickrIdOriginal);
            }
        }

        /// <summary>
        /// Gets the original Flickr id.
        /// </summary>
        public string FlickrIdOriginal
        {
            get
            {
                return _flickrIdOriginal;
            }
        }
        #endregion

        #region Public methods
        /// <summary>
        /// Returns a copy of the current instance.
        /// </summary>
        /// <returns>A copy of the current instance.</returns>
        /// <remarks>The copy is fully independent.</remarks>
        public LocalPictureMetadata GetCopy()
        {
            LocalPictureMetadata copy = new LocalPictureMetadata(this.FilePath);

            TrackChanges = false;

            copy.CopyProperties(this);

            copy.FlickrId = this.FlickrId;

            TrackChanges = true;

            return copy;
        }
        #endregion
    }
}
